package com.hp.web.controller.system;

import com.hp.common.core.controller.BaseController;
import com.hp.common.core.domain.AjaxResult;
import com.hp.common.core.page.TableDataInfo;
import com.hp.common.utils.poi.ExcelUtil;
import com.hp.system.domain.DestbationCity;
import com.hp.system.domain.IdentifyInfo;
import com.hp.system.service.DestbationCityService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/system/dest")
public class DestController extends BaseController {
    @Autowired
    private DestbationCityService destbationCityService;

    private String prefix = "system/dest";

    @RequiresPermissions("system:dest:view")
    @GetMapping()
    public String identify(){
        return prefix+"/dest";
    }

    @RequiresPermissions("system:dest:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DestbationCity destbationCity){
        startPage();
        List<DestbationCity> list = destbationCityService.selectByDest(destbationCity);
        return getDataTable(list);
    }



    @RequiresPermissions("system:dest:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
            return toAjax(destbationCityService.deleteCityByIds(ids));
    }

    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @RequiresPermissions("system:dest:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DestbationCity destbationCity){
        return toAjax(destbationCityService.insertCity(destbationCity));
    }

    @PostMapping("/checkCityNameUnique")
    @ResponseBody
    public String checkCityNameUnique(DestbationCity destbationCity){
        return destbationCityService.checkCityNameUnique(destbationCity);
    }

    @RequiresPermissions("system:passinfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DestbationCity destbationCity)
    {
        List<DestbationCity> list = destbationCityService.getDestInfoSheet(destbationCity);
        ExcelUtil<DestbationCity> util = new ExcelUtil<DestbationCity>(DestbationCity.class);
        return util.exportExcel(list, "邮路信息");
    }

    @RequiresPermissions("system:passinfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id , ModelMap mmp){
        mmp.put("destbationCity",destbationCityService.getDestById(id));
        return prefix+"/edit";
    }

    @RequiresPermissions("system:passinfo:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult saveEdit(DestbationCity destbationCity){
        return toAjax(destbationCityService.updateDest(destbationCity));
    }
}
